﻿<Window x:Class="FileDuplicateUtility.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:l="clr-namespace:FileDuplicateUtility"
        Title="File Duplicate Utility" Height="400" Width="800">
    <Window.Resources>
        <l:DebugConverter x:Key="dc"/>
        <l:SizeConverter x:Key="sc"/>

        <RoutedUICommand x:Key="CheckAllCmd" Text="Select All"/>
        <RoutedUICommand x:Key="CreateCheckedFileFilterCmd" Text="Create Filter"/>
        <RoutedUICommand x:Key="MoveCheckedFilesCmd" Text="Move Checked Files"/>
    </Window.Resources>
    <Window.DataContext>
        <Binding RelativeSource="{RelativeSource Mode=Self}" Mode="OneTime"/>
    </Window.DataContext>
    <Window.CommandBindings>
        <CommandBinding Command="Open" Executed="Browse_Executed"/>
    </Window.CommandBindings>
    <Grid Margin="5">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        
        <Grid Grid.Row="0">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="Auto" MinWidth="100"/>
            </Grid.ColumnDefinitions>
            
            <TextBlock Grid.Row="0" Grid.Column="0" VerticalAlignment="Center" Text="Folder : "/>
            <TextBox Grid.Row="0" Grid.Column="1" Margin="2,0,0,0" Text="{Binding Path=Root.FullName, Mode=OneWay}"/>
            <Button Grid.Row="0" Grid.Column="2" Margin="2" Content="Browse..." Command="Open"/>

            <TextBlock Grid.Row="1" Grid.Column="0" VerticalAlignment="Center" Text="Status : "/>
            <TextBlock Grid.Row="1" Grid.Column="1" VerticalAlignment="Center" Margin="2,2,0,0" Text="{Binding Path=Status, Mode=OneWay}"/>
            <ProgressBar Grid.Row="1" Grid.Column="2" Margin="2" VerticalAlignment="Stretch"
                         DataContext="{Binding Path=Progress, Mode=OneWay}" 
                         Minimum="0" Maximum="{Binding Path=Total, Mode=OneWay}"
                         IsIndeterminate="{Binding Path=IsIndeterminate, Mode=OneWay}" Value="{Binding Path=Current, Mode=OneWay}"/>
            <TextBlock Grid.Row="1" Grid.Column="2" VerticalAlignment="Center" HorizontalAlignment="Center" Text="{Binding Path=Progress.Percentage, StringFormat='{}{0:0.00} %'}"/>
        </Grid>
        
        <DataGrid Grid.Row="1" Margin="0,5,0,0" ItemsSource="{Binding Path=Files, Mode=OneWay}" AutoGenerateColumns="False" GridLinesVisibility="None" IsReadOnly="True">
            <DataGrid.Columns>
                <DataGridTextColumn Width="Auto" MinWidth="100" Header="Folder" Binding="{Binding Path=Parent.Name, Mode=OneTime}"/>
                <DataGridTextColumn Width="*" Header="Name" Binding="{Binding Path=Name, Mode=OneTime}"/>
                <DataGridTextColumn Width="Auto" MinWidth="100" Header="Size" Binding="{Binding Path=Size, Mode=OneTime, Converter={StaticResource sc}}"/>
            </DataGrid.Columns>
        </DataGrid>

        <DataGrid Grid.Row="2" Margin="0,5,0,0" ItemsSource="{Binding Path=Duplicates, Mode=OneWay}" AutoGenerateColumns="False" GridLinesVisibility="None" IsReadOnly="True">
            <DataGrid.ContextMenu>
                <ContextMenu>
                    <ContextMenu.CommandBindings>
                        <CommandBinding Command="{StaticResource CheckAllCmd}" Executed="CheckAllCmd_Executed"/>
                        <CommandBinding Command="{StaticResource CreateCheckedFileFilterCmd}" Executed="CreateCheckedFileFilterCmd_Executed"/>
                        <CommandBinding Command="{StaticResource MoveCheckedFilesCmd}" Executed="MoveCheckedFilesCmd_Executed"/>
                    </ContextMenu.CommandBindings>
                    <MenuItem Header="Select All" Command="{StaticResource CheckAllCmd}" CommandParameter="All" InputGestureText="Ctrl+A"/>
                    <MenuItem Header="Select None" Command="{StaticResource CheckAllCmd}" CommandParameter="None" InputGestureText="Ctrl+U"/>
                    <MenuItem Header="Apply Checked File Filter ..." Command="{StaticResource CreateCheckedFileFilterCmd}" InputGestureText="Ctrl+F"/>
                    <MenuItem Header="Move Checked Files To ..." Command="{StaticResource MoveCheckedFilesCmd}" CommandParameter="Move" InputGestureText="Ctrl+M"/>
                    <MenuItem Header="Copy Checked Files To ..." Command="{StaticResource MoveCheckedFilesCmd}" CommandParameter="Copy" InputGestureText="Ctrl+C"/>
                </ContextMenu>
            </DataGrid.ContextMenu>
            <DataGrid.RowDetailsTemplate>
                <DataTemplate>
                    <DataGrid ItemsSource="{Binding Path=Files, Mode=OneTime}" AutoGenerateColumns="False" GridLinesVisibility="None">
                        <DataGrid.Columns>
                            <DataGridTemplateColumn>
                                <DataGridTemplateColumn.CellTemplate>
                                    <DataTemplate>
                                        <CheckBox IsChecked="{Binding Path=IsChecked, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, Converter={StaticResource dc}}"/>
                                    </DataTemplate>
                                </DataGridTemplateColumn.CellTemplate>
                            </DataGridTemplateColumn>
                            <DataGridTextColumn Header="Name" IsReadOnly="True" Binding="{Binding Path=File.Name, Mode=OneTime}"/>
                        </DataGrid.Columns>
                    </DataGrid>
                </DataTemplate>
            </DataGrid.RowDetailsTemplate>
            <DataGrid.Columns>
                <DataGridTextColumn Width="*" Header="Name" Binding="{Binding Path=Name, Mode=OneTime}"/>
                <DataGridTextColumn Width="Auto" MinWidth="100" Header="Size" Binding="{Binding Path=Size, Mode=OneTime, Converter={StaticResource sc}}"/>
                <DataGridTextColumn Width="Auto" MinWidth="50" Header="Count" Binding="{Binding Path=Files.Count, Mode=OneTime}"/>
                <DataGridTextColumn Width="Auto" MinWidth="50" Header="# Checked" Binding="{Binding Path=CheckedCount, Mode=OneWay}"/>
            </DataGrid.Columns>
        </DataGrid>
    </Grid>
</Window>
